package com.arpa.wms.controller;

import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.service.IEnumInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 枚举信息 Controller
 * </p>
 *
 * @author xuyang
 * @since 2021-03-11
 * @description 主要用于给前端传递枚举类信息的，减少前端数据写死代码， 后期可改为使用字典等手段
 */
@Api(tags = "枚举类信息")
@RestController
@RequestMapping(value="/enumInfo", produces = "application/json;charset=UTF-8")
@Log4j2
public class EnumInfoController {

    @Autowired
    private IEnumInfoService iEnumInfoService;

    /**
     * 获取枚举类信息
     *
     * @param type
     * @param request
     * @return
     */
    @ApiOperation(value = "获取枚举类信息", notes = "获取枚举类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @NeedLogin
    @GetMapping("/getEnumList")
    public Result getEnumList(@RequestParam(name = "type") String type, HttpServletRequest request) {
        try {
            List<Map<String, Object>> mapList = iEnumInfoService.getEnumList(type);
            return Result.ok().data(mapList);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE, e);
            return Result.error(e.getMessage());
        }
    }

}
